package cloudalibaba.sentinel.controller;

import cloudalibaba.sentinel.myHandler.CustomerBlockHandler;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import zlx.commons.entities.CommonResult;
import zlx.commons.entities.Payment;

@RestController
public class RestLimitCtroller {
    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "HandlerExeception")
    public CommonResult byResource(){
        return new CommonResult(200,"安置原名测试OK",new Payment(200l,"serial001"));
    }
    public CommonResult HandlerExeception(BlockException exception){
        return new CommonResult(444,exception.getClass().getCanonicalName()+"\t 服务不可用");
    }
    @GetMapping("/RestLimitCtroller/byUrl")
    @SentinelResource(value = "byUrl",blockHandler = "HandlerExeception")
    public CommonResult byUrl(){
        return new CommonResult(200,"安置url测试OK",new Payment(2020l,"serial001"));
    }
    @GetMapping("/RestLimitCtroller/customerBlockHandler")
    @SentinelResource(value = "customerBlockHandler",blockHandlerClass = CustomerBlockHandler.class,blockHandler = "HandlerException2")
    public CommonResult customerBlockHandler(){
        return new CommonResult(200,"按客户自定义",new Payment(2020l,"serial001"));
    }
}
